//@ts-nocheck
import {TEXT, ELEMENT} from './constants';
import {ReactElement} from './vdom'

function createElement(type, config = {}, ...children /** ←和源码写法不一样,但一个意思*/) {
  delete config.__source;
  delete config.__self;
  //↑源码里用到了我们用不到

  const {key, ref, ...props} = config;
  let $$typeof = null;
  if(typeof type === 'string') { // 'span' 'div' 'button'
    $$typeof = ELEMENT; // 是一个原生DOM类型
  }
  props.children = children.map(item => {
    if(typeof item === 'object') {
      return item; // React.createElement('span',{color:'red'},'Hello')
    }else {
      return {$$typeof: TEXT, type: TEXT, content: item};
    }
  });

  return ReactElement($$typeof, type, key, ref, props);
}

const React = {
  createElement
};

export default React
